import auth from '../../../api/auth'
export default{
    data(){
        return{
            urlSelectedRows:[],
            urls:[]
        }
    },
    methods:{
        onAddSelfAuth(){

        },
        onUrlSelectedChange(rows){
            this.urlSelectedRows = rows;
        },
        onAddUrl(){
            this.$refs.urlDlg.show({jsbh:this.selectedRole.jsbh})
            .then((action)=>{
                if(action === 'ok'){
                    this.loadUrls();
                }
            })
        },
        onDelUrl(){
            this.$confirm('是否删除选中URL？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                closeOnClickModal:false
            }).then((action) => {
                this.delUrl();
            }).catch((action) => {
            });
        },
        delUrl(){
            if( !this.urlSelectedRows || this.urlSelectedRows.length == 0 ){
                return;
            }
            const postData = {
                bh:this.selectedRole.jsbh,
                ids:this.urlSelectedRows.map((item)=>item.url)
            }
            auth.delUrl(postData)
            .then(response => {
                const { data } = response;
                if( data.error_code == 0 ){
                    this.loadUrls();
                }else{
                    this.showError("操作失败！");
                }
            }).catch(error => {
                this.showError("本地异常！");
            });
        },
        onSelectionChange(rows){
            //console.log(rows)
            this.selectRows = rows;
        },
        loadUrls(){
            const queryData = {
                injsbh:this.selectedRole.jsbh
            }
            auth.queryUrl(queryData)
            .then(response => {
                const { data } = response;
                if( data.error_code == 0 ){
                    
                    this.urls = data.urls;
                }else{
                    this.showError("操作失败！");
                }
            }).catch(error => {
            });
        },
    }
}